﻿<!DOCTYPE html>
<html>
<head>
  <title>配偶信息</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  <meta name="apple-mobile-web-app-capable" content="yes"/>
  <link href="resources/resources/css/jquery-ui-themes.css" type="text/css" rel="stylesheet"/>
  <link href="resources/resources/css/axure_rp_page.css" type="text/css" rel="stylesheet"/>
  <link href="resources/data/styles.css" type="text/css" rel="stylesheet"/>
  <link href="resources/files/配偶信息/styles.css" type="text/css" rel="stylesheet"/>
  <link href="resources/files/个人信息/styles.css" type="text/css" rel="stylesheet"/>
  <script src="resources/resources/scripts/jquery-1.7.1.min.js"></script>
  <script src="resources/resources/scripts/jquery-ui-1.8.10.custom.min.js"></script>
  <style>
    #u310 {
      border-width:0px;
      position:absolute;
      left:515px;
      top:356px;
      width:55px;
      height:25px;
    }
    #u305 {
      border-width:0px;
      position:absolute;
      left:619px;
      top:356px;
      width:42px;
      height:25px;
    }
    #u30_div {
      border-width:0px;
      position:absolute;
      left:0px;
      top:0px;
      width:87px;
      height:25px;
      background:inherit;
      box-sizing:border-box;
      border-width:1px;
      border-style:solid;
      border-color:rgba(121, 121, 121, 1);
      border-radius:0px;
      -moz-box-shadow:none;
      -webkit-box-shadow:none;
      box-shadow:none;
    }
    #u171_div {
      border-width:0px;
      position:absolute;
      left:0px;
      top:0px;
      width:87px;
      height:25px;
      background:inherit;
      background-color:rgba(102, 102, 255, 1);
      box-sizing:border-box;
      border-width:1px;
      border-style:solid;
      border-color:rgba(121, 121, 121, 1);
      border-radius:0px;
      -moz-box-shadow:none;
      -webkit-box-shadow:none;
      box-shadow:none;
    }
  </style>
</head>
<body>
<div id="base" class="">
  <!-- Unnamed (矩形) -->
  <div id="u274" class="ax_default box_1">
    <div id="u274_div" class=""></div>
    <div id="u274_text" class="text ">
      <p><span>配偶姓名：</span></p>
    </div>
  </div>
  <form  id="form2" enctype="multipart/form-data" method="post" accept-charset="utf-8">
  <!-- Unnamed (文本框) -->
  <div id="u275" class="ax_default text_field">
    <input id="u275_input" name="name" type="text"/>
  </div>
        <!-- Unnamed (矩形) -->
        <div id="u29" class="ax_default box_1">
                <div id="u29_div" class=""></div>
                <div id="u29_text" class="text ">
                    <p><span>流动人口服务管理系统</span></p>
                </div>
            </div>

            <!-- Unnamed (矩形) -->
            <div id="u30" class="ax_default box_1">
                <div id="u30_div" class=""></div>
                <div id="u30_text" class="text ">
                    <p><span onclick="toPersonalMessage()">个人信息</span></p>
                </div>
            </div>

            <!-- Unnamed (矩形) -->
            <div id="u171" class="ax_default box_1">
                <div id="u171_div" class=""></div>
                <div id="u171_text" class="text ">
                    <p><span>配偶信息</span></p>
                </div>
            </div>

            <!-- Unnamed (矩形) -->
            <div id="u31" class="ax_default box_1">
                <div id="u31_div" class=""></div>
                <div id="u31_text" class="text ">
                    <p><span onclick="toFamilyMember()">同住家庭成员</span></p>
                </div>
            </div>

            <!-- Unnamed (矩形) -->
            <div id="u32" class="ax_default box_1">
                <div id="u32_div" class=""></div>
                <div id="u32_text" class="text ">
                    <p><span onclick="toFamilyPlanning()">计生信息</span></p>
                </div>
            </div>


            <!-- Unnamed (矩形) -->
            <div id="u172" class="ax_default box_1">
                <div id="u172_div" class=""></div>
                <div id="u172_text" class="text ">
                    <p><span onclick="toEmploymentInformation()">就业信息</span></p>
                </div>
            </div>

            <!-- Unnamed (矩形) -->
            <div id="u81" class="ax_default box_1">
                <div id="u81_div" class=""></div>
                <div id="u81_text" class="text ">
                    <p><span onclick="toDwellMessage()">居住信息</span></p>
                </div>
            </div>
        <!-- Unnamed (水平线) -->
        <div id="u170" class="ax_default line">
            <img id="u170_img" class="img " src="resources/images/个人信息/u170.png"/>
        </div>
  <!-- Unnamed (矩形) -->
  <div id="u276" class="ax_default box_1">
    <div id="u276_div" class=""></div>
    <div id="u276_text" class="text ">
      <p><span>配偶身份号码：</span></p>
    </div>
  </div>

  <!-- Unnamed (矩形) -->
  <div id="u277" class="ax_default box_1">
    <div id="u277_div" class=""></div>
    <div id="u277_text" class="text ">
      <p><span>现居住地地址：</span></p>
    </div>
  </div>

  <!-- Unnamed (文本框) -->
  <div id="u278" class="ax_default text_field">
    <input id="u278_input" name="identify" type="text" value=""/>
  </div>



  <!-- Unnamed (文本框) -->
  <div id="u297" class="ax_default text_field">
    <input id="u297_input" type="text" value=""/>
  </div>


  <!-- Unnamed (文本框) -->
  <div id="u299" class="ax_default text_field">
    <input id="u299_input" name="detailedAddress" type="text" value=""/>
  </div>

  <!-- Unnamed (文本框) -->
  <div id="u300" class="ax_default text_field">
    <input id="u300_input" type="text" value=""/>
  </div>




  <!-- Unnamed (文本框) -->
  <div id="u305" class="ax_default text_field">
    <input id="u305_input" name="nowInVillage" style="width: 98px;height: 25px" type="text" value=""/>
  </div>

  <!-- Unnamed (矩形) -->
  <div id="u306" class="ax_default box_1">
    <div id="u306_div" class=""></div>
    <div id="u306_text" class="text ">
      <p><span>村（社区）</span></p>
    </div>
  </div>

  <!-- Unnamed (矩形) -->
  <div id="u307" class="ax_default box_1">
    <div id="u307_div" class=""></div>
    <div id="u307_text" class="text ">
      <p><span>（门楼详址）</span></p>
    </div>
  </div>

  <!-- Unnamed (矩形) -->
  <div id="u308" class="ax_default box_3">
    <div id="u308_div" class=""></div>
  </div>

  <!-- Unnamed (矩形) -->
  <div id="u309" class="ax_default box_1">
    <div id="u309_div" class=""></div>
    <div id="u309_text" class="text ">
      <p><span>版权所有：公安局</span></p>
    </div>
  </div>

  <!-- Unnamed (下拉列表框) -->
  <div id="u310" class="ax_default droplist">
    <select id="nowInTownship" style="width: 98px;height: 25px;" name="nowInTownship" >
      <option value="">请选择镇</option>
    </select>
  </div>

  <!-- Unnamed (下拉列表框) -->
  <div id="u311" class="ax_default droplist">
    <select id="nowInCounty" style="width: 98px;height: 25px;"  onclick="changship()" name="nowInCounty">
      <option value="">请选择乡</option>
    </select>
  </div>

  <!-- Unnamed (下拉列表框) -->
  <div id="u312" class="ax_default droplist">
    <select id="nowInCity" style="width: 98px;height: 25px;" onclick="changCount()" name="nowInCity">
      <option value="">请选择市</option>
    </select>
  </div>

  <!-- Unnamed (下拉列表框) -->
  <div id="u313" class="ax_default droplist">
    <select id="nowInProvince" style="width: 98px;height: 25px;"  onclick="changeCity()" name="nowInProvince">
      <option value="">请选择省</option>
    </select>
  </div>

  <!-- Unnamed (矩形) -->
  <div id="u314" class="ax_default box_1">
    <div id="u314_div" class=""></div>
    <div id="u314_text" class="text ">
      <p><span>本人联系电话：</span></p>
    </div>
  </div>
  <!-- Unnamed (文本框) -->
  <div id="u315" class="ax_default text_field">
    <input id="u315_input" name="contactPhone" type="text" value=""/>
  </div>

  <!-- Unnamed (矩形) -->
  <div id="u316" class="ax_default box_1">
    <div id="u316_div" class=""></div>
    <div id="u316_text" class="text ">
      <p><span>工作单位：</span></p>
    </div>
  </div>

  <!-- Unnamed (文本框) -->
  <div id="u317" class="ax_default text_field">
    <input id="u317_input" name="workingUnit" type="text" value=""/>
  </div>



  <!-- Unnamed (矩形) -->
  <div id="u319" class="ax_default box_1">
    <div id="u319_div" class=""></div>
    <div id="u319_text" class="text ">
      <p><span>从业状况：</span></p>
    </div>
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u320" class="ax_default radio_button">
    <label for="u320_input" style="position: absolute; left: 0px;">
      <div id="u320_text" class="text ">
        <p><span>国家机关</span></p>
      </div>
    </label>
    <input id="u320_input" type="radio" value="36" name="workingConditions"/>
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u321" class="ax_default radio_button">
    <label for="u321_input" style="position: absolute; left: 0px;">
      <div id="u321_text" class="text ">
        <p><span>企、事业单位</span></p>
      </div>
    </label>
    <input id="u321_input" type="radio" value="37" name="workingConditions"/>
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u322" class="ax_default radio_button">
    <label for="u322_input" style="position: absolute; left: 0px;">
      <div id="u322_text" class="text ">
        <p><span>自由职业</span></p>
      </div>
    </label>
    <input id="u322_input" type="radio" value="38" name="workingConditions"/>
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u323" class="ax_default radio_button">
    <label for="u323_input" style="position: absolute; left: 0px;">
      <div id="u323_text" class="text ">
        <p><span>民营（个体）</span></p>
      </div>
    </label>
    <input id="u323_input" type="radio" value="39" name="workingConditions"/>
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u324" class="ax_default radio_button">
    <label for="u324_input" style="position: absolute; left: 0px;">
      <div id="u324_text" class="text ">
        <p><span>离（退）休</span></p>
      </div>
    </label>
    <input id="u324_input" type="radio" value="40" name="workingConditions"/>
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u325" class="ax_default radio_button">
    <label for="u325_input" style="position: absolute; left: 0px;">
      <div id="u325_text" class="text ">
        <p><span>无业</span></p>
      </div>
    </label>
    <input id="u325_input" type="radio" value="43" name="workingConditions"/>
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u326" class="ax_default radio_button">
    <label for="u326_input" style="position: absolute; left: 0px;">
      <div id="u326_text" class="text ">
        <p><span>其他</span></p>
      </div>
    </label>
    <input id="u326_input" type="radio" value="44" name="workingConditions" />
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u327" class="ax_default radio_button">
    <label for="u327_input" style="position: absolute; left: 0px;">
      <div id="u327_text" class="text ">
        <p><span>学生</span></p>
      </div>
    </label>
    <input id="u327_input" type="radio" value="41" name="workingConditions" />
  </div>

  <!-- Unnamed (单选按钮) -->
  <div id="u328" class="ax_default radio_button">
    <label for="u328_input" style="position: absolute; left: 0px;">
      <div id="u328_text" class="text ">
        <p><span>农民</span></p>
      </div>
    </label>
    <input id="u328_input" type="radio" value="42" name="workingConditions" />
  </div>
  <input id="id" type="hidden">
  </form>




  <!-- Unnamed (矩形) -->
  <div id="u335" class="ax_default button">
    <div id="u335_div" class=""></div>
    <div id="u335_text" class="text ">
      <span><a onclick="peiou()" class="baocun">保存</a></span>
    </div>
  </div>

</div>
</body>
</html>
<script>
  var id = "";
  var employmentMessageId = "";
  var dwellMessageId = "";
  var planingId = "";
  var spouse = "";
  var provinceCode = "";
  $(function() {
      id = location.href.split("personalId=")[1];
      if(id.includes("&")){
          id = id.split("&")[0];
      }
      $.ajax({
        url:"/findPersonalMessageById",
        data:{id:id},
        dataType:"json",
        type:"post",
        async:false,
        success:function(data) {
          employmentMessageId = data.employmentMessageId;
          dwellMessageId = data.dwellMessageId;
          planingId = data.familyPlanningId;
          spouse = data.spouse;
          provinceCode = data.nowInProvince;
        }
      })
      $.ajaxSettings.async = false;
      $.getJSON("/selectProvince",{},function (data) {
          $("#nowInProvince").empty();
          var sheng='<option value="">请选择</option>';
          for(var i=0;i<data.length;i++){
              var s=data[i];
            sheng+='<option value="'+s.code+'">'+s.name+'</option>';
          }
          $("#nowInProvince").append(sheng);
      })
      if(spouse!=undefined&&spouse!=""&&spouse!=null){
          findSpouseById(spouse);
      }
  })
  /**
   * 不为空
   */
  function checkText(dom,reg,tip,tip2) {
      if(dom.val()==""||dom.val()==null){
          alert(tip)
          return false;
      }else if(!reg.test(dom.val())){
          alert(tip2)
          return false;
      }
      return true;
  }
  /**
   * 可为空
   */
  function checkTextNull(dom,reg,tip2) {
      if(dom.val()==""||dom.val()==null){
          return true;
      }else if(!reg.test(dom.val())){
          alert(tip2);
          return false;
      }
      return true;
  }
  function changeCity() {
      $.ajaxSettings.async = false;
      var code=$("#nowInProvince").val();
      $.getJSON("/selectCity",{"code":code},function (data) {
          $("#nowInCity").empty();
          var shi='<option value="">请选择</option>';
          for (var i=0;i<data.length;i++){
              var s=data[i];
              shi+='<option value="'+s.code+'">'+s.name+'</option>';
          }
          $("#nowInCity").append(shi);
      })
  }
  function changCount() {
      $.ajaxSettings.async = false;
      var code=$("#nowInCity").val();
      $.getJSON("/selectCounty",{"code":code},function (data) {
          $("#nowInCounty").empty();
          var xian='<option value="">请选择</option>';
          for (var i=0;i<data.length;i++){
              var s=data[i];
              xian+='<option value="'+s.code+'">'+s.name+'</option>';
          }
          $("#nowInCounty").append(xian);
      })
  }
  function changship() {
      $.ajaxSettings.async = false;
      var code=$("#nowInCounty").val();
      $.getJSON("/selectTownship",{"code":code},function (data) {
          $("#nowInTownship").empty();
          var ship='<option value="">请选择</option>';
          for(var i=0;i<data.length;i++){
              var s=data[i];
              ship+='<option value="'+s.code+'">'+s.name+'</option>';
          }
          $("#nowInTownship").append(ship);
      })
  }
  function peiou() {
      if(!checkText($("input[name='name']"),/^[\u4E00-\u9FA5\uf900-\ufa2d·\s]{2,20}$/,"姓名不能为空","姓名格式错误")){
          return;
      }
      if(!checkTextNull($("input[name='identify']"),/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,"身份证格式错误")){
          return;
      }
      if($("select[id='nowInProvince']").val() == null || $("select[id='nowInProvince']").val() == ""){
          alert("请选择省！")
          return;
      }
      if($("select[id='nowInCity']").val() == null || $("select[id='nowInCity']").val() == ""){
          alert("请选择市！")
          return;
      }
      if($("select[id='nowInCounty']").val() == null || $("select[id='nowInCounty']").val() == ""){
          alert("请选择县！")
          return;
      }
      if($("select[id='nowInTownship']").val() == null || $("select[id='nowInTownship']").val() == ""){
          alert("请选择镇！")
          return;
      }
      if($("input[id='u305_input']").val() == null || $("input[id='u305_input']").val() == ""){
          alert("请输入村（社区）！")
          return;
      }
      if($("input[id='u317_input']").val() == null || $("input[id='u317_input']").val() == ""){
          alert("请输入工作单位！")
          return;
      }
      if(!checkTextNull($("input[id='u315_input']"),/^1[3456789]\d{9}$/,"手机格式错误")){
          return;
      }
      var formdata= new FormData($("#form2")[0]);
      var personalId = location.href.split("personalId=")[1];
      if(personalId.includes("&")){
          personalId = personalId.split("&")[0];
      }
      formdata.append("id",$("#id").val());
      formdata.append("personalId",personalId);
      console.log(formdata);
      $.ajax({
          url:"/inserts",
          data:formdata,
          type:"post",
          async:false,
          dataType:"json",
          processData:false,
          contentType:false,
          success:function (data) {
              $("#id").val(data.id);
              //更新个人信息表
              $.ajax({
                url:"/updatePersonalInformation",
                data:{id:personalId,spouse:data.id},
                dataType:"json",
                type:"post"
              })
              alert("添加成功");
              toFamilyMember();
          }
      })
  }
  function findSpouseById(id) {
      $.ajax({
          url:"/findSpouseById",
          data:{id:id},
          dataType:"json",
          type:"post",
          async:false,
          success:function(data) {
              $("input[name='name']").val(data.name);
              $("input[name='identify']").val(data.identify);
              $("select[name='sex']").val(data.sex);
              $("select[name='nowInProvince']").val(data.nowInProvince);
              changeCity();
              $("select[name='nowInCity']").val(data.nowInCity);
              changCount();
              $("select[name='nowInCounty']").val(data.nowInCounty);
              changship();
              $("select[name='nowInTownship']").val(data.nowInTownship);
              $("input[name='nowInVillage']").val(data.nowInVillage);
              $("input[name='detailedAddress']").val(data.detailedAddress);
              $("input[name='workingUnit']").val(data.workingUnit);
              $("input[name='contactPhone']").val(data.contactPhone);
              $.each($("input[name='workingConditions']"),function(index,item) {//遍历单选框
                  if($(item).val()==data.workingConditions){//如果为要选的值
                      $(item).attr("checked","checked");//赋值
                  }
              })
              $("#id").val(data.id);
          }
      })
  }
  /**
   * 跳转到个人信息，传个人信息id
   */
  function toPersonalMessage() {
      var url = location.href; //获取url中"?"符后的字串
      var personalId = url.split("=")[1].split("&")[0];
      if($("#id").val()!=null&&$("#id").val()!=""){
          window.location = "/toPersonalInformation?id="+personalId+"&spouse="+$("#id").val();
      }else {
          window.location = "/toPersonalInformation?id="+personalId;
      }
  }
    /**
     * 跳转到居住信息，传递省码
     */
    function toDwellMessage() {
        if(dwellMessageId!=''&&dwellMessageId!=null){
            window.location = "/toDwellMessage?personalId="+id+"&provinceCode="+provinceCode+"&dwellMessageId="+dwellMessageId;
            return;
        }
        window.location = "/toDwellMessage?personalId="+id+"&provinceCode="+provinceCode;
    }
    /**
     * 跳转到计生信息，传递省码
     */
    function toFamilyPlanning() {
        if(planingId!=''&&planingId!=null){
            window.location = "/toFamilyPlanning?personalId="+id+"&provinceCode="+provinceCode+"&planingId="+planingId;
            return;
        }
        window.location = "/toFamilyPlanning?personalId="+id+"&provinceCode="+provinceCode;
    }
    /**
     * 跳转到成员信息，传递省码 TODO
     */
    function toFamilyMember() {
       window.location = "/toFamilyMember?personalId="+id;
    }
    /**
     * 跳转到就业信息，传递省码
     */
    function toEmploymentInformation() {
            if(employmentMessageId!=''&&employmentMessageId!=null){
                window.location = "/toEmploymentInformation?personalId="+id+"&provinceCode="+provinceCode+"&employmentMessageId="+employmentMessageId;
                return;
            }
            window.location = "/toEmploymentInformation?personalId="+id+"&provinceCode="+provinceCode;
    }
</script>